﻿namespace TC
{
    [Menu("Function/Delay")]
    public class Delay : FunctionNode, IUpdate
    {
        public float interval = 5;
        private float cur = 0;
        private bool called = false;
        
        public void OnUpdate(float delta)
        {
            if (called) return;

            cur += delta;
            if (cur >= interval)
            {
                called = true;
                chain.Call(flowOut);
            }
        }

        public override void Stop()
        {
            base.Stop();

            called = false;
            cur = 0;
        }
    }
}
